package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StuCompetition;
import com.ruoyi.system.service.IStuCompetitionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 竞赛获奖Controller
 * 
 * @author ruoyi
 * @date 2024-01-09
 */
@Controller
@RequestMapping("/system/competition")
public class StuCompetitionController extends BaseController
{
    private String prefix = "system/competition";

    @Autowired
    private IStuCompetitionService stuCompetitionService;

    @RequiresPermissions("system:competition:view")
    @GetMapping()
    public String competition()
    {
        return prefix + "/competition";
    }

    /**
     * 查询竞赛获奖列表
     */
    @RequiresPermissions("system:competition:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StuCompetition stuCompetition)
    {
        startPage();
        List<StuCompetition> list = stuCompetitionService.selectStuCompetitionList(stuCompetition);
        return getDataTable(list);
    }

    /**
     * 导出竞赛获奖列表
     */
    @RequiresPermissions("system:competition:export")
    @Log(title = "竞赛获奖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StuCompetition stuCompetition)
    {
        List<StuCompetition> list = stuCompetitionService.selectStuCompetitionList(stuCompetition);
        ExcelUtil<StuCompetition> util = new ExcelUtil<StuCompetition>(StuCompetition.class);
        return util.exportExcel(list, "竞赛获奖数据");
    }

    /**
     * 新增竞赛获奖
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存竞赛获奖
     */
    @RequiresPermissions("system:competition:add")
    @Log(title = "竞赛获奖", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StuCompetition stuCompetition)
    {
        return toAjax(stuCompetitionService.insertStuCompetition(stuCompetition));
    }

    /**
     * 修改竞赛获奖
     */
    @RequiresPermissions("system:competition:edit")
    @GetMapping("/edit/{comId}")
    public String edit(@PathVariable("comId") Long comId, ModelMap mmap)
    {
        StuCompetition stuCompetition = stuCompetitionService.selectStuCompetitionByComId(comId);
        mmap.put("stuCompetition", stuCompetition);
        return prefix + "/edit";
    }

    /**
     * 修改保存竞赛获奖
     */
    @RequiresPermissions("system:competition:edit")
    @Log(title = "竞赛获奖", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StuCompetition stuCompetition)
    {
        return toAjax(stuCompetitionService.updateStuCompetition(stuCompetition));
    }

    /**
     * 删除竞赛获奖
     */
    @RequiresPermissions("system:competition:remove")
    @Log(title = "竞赛获奖", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stuCompetitionService.deleteStuCompetitionByComIds(ids));
    }
}
